<%@ Control %>
<script language="VB" runat="server">
Dim m_Secure As Boolean = False
Public WelcomeMessage As String = "Welcome"
Sub Login_Click(ByVal sender As Object, ByVal e As EventArgs)
If UsernameValidator.IsValid And PasswordValidator.IsValid Then
UnsecurePanel.Visible = False
Message.Text = WelcomeMessage & ", " & UserName.Text
SecurePanel.Visible = True
m_Secure = True
Dim evt As new EventArgs()
OnLogin(evt)
End If
End Sub
Sub Logout_Click(ByVal sender As Object, ByVal e As EventArgs)
If UsernameValidator.IsValid And PasswordValidator.IsValid Then
Logoff()
End If
End Sub
Public ReadOnly Property Secure() As Boolean
Get
Return m_Secure
End Get
End Property
Public ReadOnly Property User() As String
Get
Return UserName.Text
End Get
End Property
Public Sub Logoff()
UnsecurePanel.Visible = True
UserName.Text = ""
Password.Text = ""
SecurePanel.Visible = False
m_Secure = False
Dim evt As new EventArgs()
OnLogout(evt)
End Sub
' Delegate declaration
Public Delegate Sub LoginHandler(ByVal sender As Object, ByVal e As EventArgs)
' Event declaration
Public Event Login As LoginHandler
' Raise the event by invoking the delegate,
' sending "me", the current instance of the class.
Protected Sub OnLogin(ByVal e As EventArgs)
RaiseEvent Login(me, e) 'Invokes the delegates.
End Sub
' Delegate declaration
Public Delegate Sub LogoutHandler(ByVal sender As Object, ByVal e As EventArgs)
' Event declaration
Public Event Logout As LogoutHandler
' Raise the event by invoking the delegate,
' sending "me", the current instance of the class.
Protected Sub OnLogout(ByVal e As EventArgs)
RaiseEvent Logout(me, e) 'Invokes the delegates.
End Sub
</script>
<asp:panel id="UnsecurePanel" runat="Server">
<asp:label runat="server" font-size="9pt">Username: </asp:label><br><asp:textbox id="UserName" runat="server" /><br>
<asp:requiredfieldvalidator id="UsernameValidator" runat="server" controltovalidate="UserName" errormessage="Please enter a username" style="color: red; font-size: 8pt" /><br>
<asp:label runat="server" font-size="9pt">Password: </asp:label><br><asp:textbox id="Password" runat="server" textmode="Password" /><br>
<asp:requiredfieldvalidator id="PasswordValidator" runat="server" controltovalidate="Password" errormessage="Please enter a password" style="color: red; font-size: 8pt" /><br>
<asp:button id="LoginButton" text="Login" runat="server" onclick="Login_Click"/>
</asp:panel>
<asp:panel id="SecurePanel" runat="Server" visible="false">
<asp:label id="Message" runat="server"/><br>
<asp:linkbutton id="LogoutButton" runat="server" onclick="Logout_Click" text="Logout" style="font-size: 8pt; color: blue;"/>
</asp:panel>